<!DOCTYPE html><html><head><meta charset="utf-8"><style>body {
  width: 45em;
  border: 1px solid #ddd;
  outline: 1300px solid #fff;
  margin: 16px auto;
}

body .markdown-body
{
  padding: 30px;
}

@font-face {
  font-family: fontawesome-mini;
  src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAzUABAAAAAAFNgAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABbAAAABwAAAAcZMzaOEdERUYAAAGIAAAAHQAAACAAOQAET1MvMgAAAagAAAA+AAAAYHqhde9jbWFwAAAB6AAAAFIAAAFa4azkLWN2dCAAAAI8AAAAKAAAACgFgwioZnBnbQAAAmQAAAGxAAACZVO0L6dnYXNwAAAEGAAAAAgAAAAIAAAAEGdseWYAAAQgAAAFDgAACMz7eroHaGVhZAAACTAAAAAwAAAANgWEOEloaGVhAAAJYAAAAB0AAAAkDGEGa2htdHgAAAmAAAAAEwAAADBEgAAQbG9jYQAACZQAAAAaAAAAGgsICJBtYXhwAAAJsAAAACAAAAAgASgBD25hbWUAAAnQAAACZwAABOD4no+3cG9zdAAADDgAAABsAAAAmF+yXM9wcmVwAAAMpAAAAC4AAAAusPIrFAAAAAEAAAAAyYlvMQAAAADLVHQgAAAAAM/u9uZ4nGNgZGBg4ANiCQYQYGJgBEJuIGYB8xgABMMAPgAAAHicY2Bm42OcwMDKwMLSw2LMwMDQBqGZihmiwHycoKCyqJjB4YPDh4NsDP+BfNb3DIuAFCOSEgUGRgAKDgt4AAB4nGNgYGBmgGAZBkYGEAgB8hjBfBYGCyDNxcDBwMTA9MHhQ9SHrA8H//9nYACyQyFs/sP86/kX8HtB9UIBIxsDXICRCUgwMaACRoZhDwA3fxKSAAAAAAHyAHABJQB/AIEAdAFGAOsBIwC/ALgAxACGAGYAugBNACcA/wCIeJxdUbtOW0EQ3Q0PA4HE2CA52hSzmZDGe6EFCcTVjWJkO4XlCGk3cpGLcQEfQIFEDdqvGaChpEibBiEXSHxCPiESM2uIojQ7O7NzzpkzS8qRqn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fgF0r/zJQB4nG2JUQuCQBCEd07TTg36fb2IyBaLd3vWaUh/vmSJnvpgmG8YcmS8X3Shf3R7QA4OBUocUKHGER5NNbOOEvwc1txnuWkTRb/aPjimJ5vXabI+3VfOiyS15UWvyezM2xiGOPyuMohOH8O8JiO4Af+FsAGNAEuwCFBYsQEBjlmxRgYrWCGwEFlLsBRSWCGwgFkdsAYrXFhZsBQrAAA=) format('woff');
}

@font-face {
  font-family: octicons-anchor;
  src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAYcAA0AAAAACjQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABwAAAAca8vGTk9TLzIAAAFMAAAARAAAAFZG1VHVY21hcAAAAZAAAAA+AAABQgAP9AdjdnQgAAAB0AAAAAQAAAAEACICiGdhc3AAAAHUAAAACAAAAAj//wADZ2x5ZgAAAdwAAADRAAABEKyikaNoZWFkAAACsAAAAC0AAAA2AtXoA2hoZWEAAALgAAAAHAAAACQHngNFaG10eAAAAvwAAAAQAAAAEAwAACJsb2NhAAADDAAAAAoAAAAKALIAVG1heHAAAAMYAAAAHwAAACABEAB2bmFtZQAAAzgAAALBAAAFu3I9x/Nwb3N0AAAF/AAAAB0AAAAvaoFvbwAAAAEAAAAAzBdyYwAAAADP2IQvAAAAAM/bz7t4nGNgZGFgnMDAysDB1Ml0hoGBoR9CM75mMGLkYGBgYmBlZsAKAtJcUxgcPsR8iGF2+O/AEMPsznAYKMwIkgMA5REMOXicY2BgYGaAYBkGRgYQsAHyGMF8FgYFIM0ChED+h5j//yEk/3KoSgZGNgYYk4GRCUgwMaACRoZhDwCs7QgGAAAAIgKIAAAAAf//AAJ4nHWMMQrCQBBF/0zWrCCIKUQsTDCL2EXMohYGSSmorScInsRGL2DOYJe0Ntp7BK+gJ1BxF1stZvjz/v8DRghQzEc4kIgKwiAppcA9LtzKLSkdNhKFY3HF4lK69ExKslx7Xa+vPRVS43G98vG1DnkDMIBUgFN0MDXflU8tbaZOUk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1xHzTXRqgKzek/mb7nB8RZTCDhGEX3kK/8Q75AmUM/eLkfA+0Hi908Kx4eNsMgudg5GLdRD7a84npi+YxNr5i5KIbW5izXas7cHXIMAau1OueZhfj+cOcP3P8MNIWLyYOBuxL6DRylJ4cAAAB4nGNgYoAALjDJyIAOWMCiTIxMLDmZedkABtIBygAAAA==) format('woff');
}

.markdown-body {
  font-family: sans-serif;
  -ms-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  color: #333333;
  overflow: hidden;
  font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  word-wrap: break-word;
}

.markdown-body a {
  background: transparent;
}

.markdown-body a:active,
.markdown-body a:hover {
  outline: 0;
}

.markdown-body b,
.markdown-body strong {
  font-weight: bold;
}

.markdown-body mark {
  background: #ff0;
  color: #000;
  font-style: italic;
  font-weight: bold;
}

.markdown-body sub,
.markdown-body sup {
  font-size: 75%;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}
.markdown-body sup {
  top: -0.5em;
}
.markdown-body sub {
  bottom: -0.25em;
}

.markdown-body h1 {
  font-size: 2em;
  margin: 0.67em 0;
}

.markdown-body img {
  border: 0;
}

.markdown-body hr {
  -moz-box-sizing: content-box;
  box-sizing: content-box;
  height: 0;
}

.markdown-body pre {
  overflow: auto;
}

.markdown-body code,
.markdown-body kbd,
.markdown-body pre,
.markdown-body samp {
  font-family: monospace, monospace;
  font-size: 1em;
}

.markdown-body input {
  color: inherit;
  font: inherit;
  margin: 0;
}

.markdown-body html input[disabled] {
  cursor: default;
}

.markdown-body input {
  line-height: normal;
}

.markdown-body input[type="checkbox"] {
  box-sizing: border-box;
  padding: 0;
}

.markdown-body table {
  border-collapse: collapse;
  border-spacing: 0;
}

.markdown-body td,
.markdown-body th {
  padding: 0;
}

.markdown-body .codehilitetable {
  border: 0;
  border-spacing: 0;
}

.markdown-body .codehilitetable tr {
  border: 0;
}

.markdown-body .codehilitetable pre,
.markdown-body .codehilitetable div.codehilite {
  margin: 0;
}

.markdown-body .linenos,
.markdown-body .code,
.markdown-body .codehilitetable td {
  border: 0;
  padding: 0;
}

.markdown-body td:not(.linenos) .linenodiv {
  padding: 0 !important;
}

.markdown-body .code {
  width: 100%;
}

.markdown-body .linenos div pre,
.markdown-body .linenodiv pre,
.markdown-body .linenodiv {
  border: 0;
  -webkit-border-radius: 0;
  -moz-border-radius: 0;
  border-radius: 0;
  -webkit-border-top-left-radius: 3px;
  -webkit-border-bottom-left-radius: 3px;
  -moz-border-radius-topleft: 3px;
  -moz-border-radius-bottomleft: 3px;
  border-top-left-radius: 3px;
  border-bottom-left-radius: 3px;
}

.markdown-body .code div pre,
.markdown-body .code div {
  border: 0;
  -webkit-border-radius: 0;
  -moz-border-radius: 0;
  border-radius: 0;
  -webkit-border-top-right-radius: 3px;
  -webkit-border-bottom-right-radius: 3px;
  -moz-border-radius-topright: 3px;
  -moz-border-radius-bottomright: 3px;
  border-top-right-radius: 3px;
  border-bottom-right-radius: 3px;
}

.markdown-body * {
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.markdown-body input {
  font: 13px Helvetica, arial, freesans, clean, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
  line-height: 1.4;
}

.markdown-body a {
  color: #4183c4;
  text-decoration: none;
}

.markdown-body a:hover,
.markdown-body a:focus,
.markdown-body a:active {
  text-decoration: underline;
}

.markdown-body hr {
  height: 0;
  margin: 15px 0;
  overflow: hidden;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #ddd;
}

.markdown-body hr:before,
.markdown-body hr:after {
  display: table;
  content: " ";
}

.markdown-body hr:after {
  clear: both;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 15px;
  margin-bottom: 15px;
  line-height: 1.1;
}

.markdown-body h1 {
  font-size: 30px;
}

.markdown-body h2 {
  font-size: 21px;
}

.markdown-body h3 {
  font-size: 16px;
}

.markdown-body h4 {
  font-size: 14px;
}

.markdown-body h5 {
  font-size: 12px;
}

.markdown-body h6 {
  font-size: 11px;
}

.markdown-body blockquote {
  margin: 0;
}

.markdown-body ul,
.markdown-body ol {
  padding: 0;
  margin-top: 0;
  margin-bottom: 0;
}

.markdown-body ol ol,
.markdown-body ul ol {
  list-style-type: lower-roman;
}

.markdown-body ul ul ol,
.markdown-body ul ol ol,
.markdown-body ol ul ol,
.markdown-body ol ol ol {
  list-style-type: lower-alpha;
}

.markdown-body dd {
  margin-left: 0;
}

.markdown-body code,
.markdown-body pre,
.markdown-body samp {
  font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
  font-size: 12px;
}

.markdown-body pre {
  margin-top: 0;
  margin-bottom: 0;
}

.markdown-body kbd {
  background-color: #e7e7e7;
  background-image: -moz-linear-gradient(#fefefe, #e7e7e7);
  background-image: -webkit-linear-gradient(#fefefe, #e7e7e7);
  background-image: linear-gradient(#fefefe, #e7e7e7);
  background-repeat: repeat-x;
  border-radius: 2px;
  border: 1px solid #cfcfcf;
  color: #000;
  padding: 3px 5px;
  line-height: 10px;
  font: 11px Consolas, "Liberation Mono", Menlo, Courier, monospace;
  display: inline-block;
}

.markdown-body>*:first-child {
  margin-top: 0 !important;
}

.markdown-body>*:last-child {
  margin-bottom: 0 !important;
}

.markdown-body .headeranchor-link {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  display: block;
  padding-right: 6px;
  padding-left: 30px;
  margin-left: -30px;
}

.markdown-body .headeranchor-link:focus {
  outline: none;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  position: relative;
  margin-top: 1em;
  margin-bottom: 16px;
  font-weight: bold;
  line-height: 1.4;
}

.markdown-body h1 .headeranchor,
.markdown-body h2 .headeranchor,
.markdown-body h3 .headeranchor,
.markdown-body h4 .headeranchor,
.markdown-body h5 .headeranchor,
.markdown-body h6 .headeranchor {
  display: none;
  color: #000;
  vertical-align: middle;
}

.markdown-body h1:hover .headeranchor-link,
.markdown-body h2:hover .headeranchor-link,
.markdown-body h3:hover .headeranchor-link,
.markdown-body h4:hover .headeranchor-link,
.markdown-body h5:hover .headeranchor-link,
.markdown-body h6:hover .headeranchor-link {
  height: 1em;
  padding-left: 8px;
  margin-left: -30px;
  line-height: 1;
  text-decoration: none;
}

.markdown-body h1:hover .headeranchor-link .headeranchor,
.markdown-body h2:hover .headeranchor-link .headeranchor,
.markdown-body h3:hover .headeranchor-link .headeranchor,
.markdown-body h4:hover .headeranchor-link .headeranchor,
.markdown-body h5:hover .headeranchor-link .headeranchor,
.markdown-body h6:hover .headeranchor-link .headeranchor {
  display: inline-block;
}

.markdown-body h1 {
  padding-bottom: 0.3em;
  font-size: 2.25em;
  line-height: 1.2;
  border-bottom: 1px solid #eee;
}

.markdown-body h2 {
  padding-bottom: 0.3em;
  font-size: 1.75em;
  line-height: 1.225;
  border-bottom: 1px solid #eee;
}

.markdown-body h3 {
  font-size: 1.5em;
  line-height: 1.43;
}

.markdown-body h4 {
  font-size: 1.25em;
}

.markdown-body h5 {
  font-size: 1em;
}

.markdown-body h6 {
  font-size: 1em;
  color: #777;
}

.markdown-body p,
.markdown-body blockquote,
.markdown-body ul,
.markdown-body ol,
.markdown-body dl,
.markdown-body table,
.markdown-body pre,
.markdown-body .admonition {
  margin-top: 0;
  margin-bottom: 16px;
}

.markdown-body hr {
  height: 4px;
  padding: 0;
  margin: 16px 0;
  background-color: #e7e7e7;
  border: 0 none;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 2em;
}

.markdown-body ul ul,
.markdown-body ul ol,
.markdown-body ol ol,
.markdown-body ol ul {
  margin-top: 0;
  margin-bottom: 0;
}

.markdown-body li>p {
  margin-top: 16px;
}

.markdown-body dl {
  padding: 0;
}

.markdown-body dl dt {
  padding: 0;
  margin-top: 16px;
  font-size: 1em;
  font-style: italic;
  font-weight: bold;
}

.markdown-body dl dd {
  padding: 0 16px;
  margin-bottom: 16px;
}

.markdown-body blockquote {
  padding: 0 15px;
  color: #777;
  border-left: 4px solid #ddd;
}

.markdown-body blockquote>:first-child {
  margin-top: 0;
}

.markdown-body blockquote>:last-child {
  margin-bottom: 0;
}

.markdown-body table {
  display: block;
  width: 100%;
  overflow: auto;
  word-break: normal;
  word-break: keep-all;
}

.markdown-body table th {
  font-weight: bold;
}

.markdown-body table th,
.markdown-body table td {
  padding: 6px 13px;
  border: 1px solid #ddd;
}

.markdown-body table tr {
  background-color: #fff;
  border-top: 1px solid #ccc;
}

.markdown-body table tr:nth-child(2n) {
  background-color: #f8f8f8;
}

.markdown-body img {
  max-width: 100%;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.markdown-body code,
.markdown-body samp {
  padding: 0;
  padding-top: 0.2em;
  padding-bottom: 0.2em;
  margin: 0;
  font-size: 85%;
  background-color: rgba(0,0,0,0.04);
  border-radius: 3px;
}

.markdown-body code:before,
.markdown-body code:after {
  letter-spacing: -0.2em;
  content: "\00a0";
}

.markdown-body pre>code {
  padding: 0;
  margin: 0;
  font-size: 100%;
  word-break: normal;
  white-space: pre;
  background: transparent;
  border: 0;
}

.markdown-body .codehilite {
  margin-bottom: 16px;
}

.markdown-body .codehilite pre,
.markdown-body pre {
  padding: 16px;
  overflow: auto;
  font-size: 85%;
  line-height: 1.45;
  background-color: #f7f7f7;
  border-radius: 3px;
}

.markdown-body .codehilite pre {
  margin-bottom: 0;
  word-break: normal;
}

.markdown-body pre {
  word-wrap: normal;
}

.markdown-body pre code {
  display: inline;
  max-width: initial;
  padding: 0;
  margin: 0;
  overflow: initial;
  line-height: inherit;
  word-wrap: normal;
  background-color: transparent;
  border: 0;
}

.markdown-body pre code:before,
.markdown-body pre code:after {
  content: normal;
}

/* Admonition */
.markdown-body .admonition {
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  position: relative;
  border-radius: 3px;
  border: 1px solid #e0e0e0;
  border-left: 6px solid #333;
  padding: 10px 10px 10px 30px;
}

.markdown-body .admonition table {
  color: #333;
}

.markdown-body .admonition p {
  padding: 0;
}

.markdown-body .admonition-title {
  font-weight: bold;
  margin: 0;
}

.markdown-body .admonition>.admonition-title {
  color: #333;
}

.markdown-body .attention>.admonition-title {
  color: #a6d796;
}

.markdown-body .caution>.admonition-title {
  color: #d7a796;
}

.markdown-body .hint>.admonition-title {
  color: #96c6d7;
}

.markdown-body .danger>.admonition-title {
  color: #c25f77;
}

.markdown-body .question>.admonition-title {
  color: #96a6d7;
}

.markdown-body .note>.admonition-title {
  color: #d7c896;
}

.markdown-body .admonition:before,
.markdown-body .attention:before,
.markdown-body .caution:before,
.markdown-body .hint:before,
.markdown-body .danger:before,
.markdown-body .question:before,
.markdown-body .note:before {
  font: normal normal 16px fontawesome-mini;
  -moz-osx-font-smoothing: grayscale;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  line-height: 1.5;
  color: #333;
  position: absolute;
  left: 0;
  top: 0;
  padding-top: 10px;
  padding-left: 10px;
}

.markdown-body .admonition:before {
  content: "\f056\00a0";
  color: 333;
}

.markdown-body .attention:before {
  content: "\f058\00a0";
  color: #a6d796;
}

.markdown-body .caution:before {
  content: "\f06a\00a0";
  color: #d7a796;
}

.markdown-body .hint:before {
  content: "\f05a\00a0";
  color: #96c6d7;
}

.markdown-body .danger:before {
  content: "\f057\00a0";
  color: #c25f77;
}

.markdown-body .question:before {
  content: "\f059\00a0";
  color: #96a6d7;
}

.markdown-body .note:before {
  content: "\f040\00a0";
  color: #d7c896;
}

.markdown-body .admonition::after {
  content: normal;
}

.markdown-body .attention {
  border-left: 6px solid #a6d796;
}

.markdown-body .caution {
  border-left: 6px solid #d7a796;
}

.markdown-body .hint {
  border-left: 6px solid #96c6d7;
}

.markdown-body .danger {
  border-left: 6px solid #c25f77;
}

.markdown-body .question {
  border-left: 6px solid #96a6d7;
}

.markdown-body .note {
  border-left: 6px solid #d7c896;
}

.markdown-body .admonition>*:first-child {
  margin-top: 0 !important;
}

.markdown-body .admonition>*:last-child {
  margin-bottom: 0 !important;
}

/* progress bar*/
.markdown-body .progress {
  display: block;
  width: 300px;
  margin: 10px 0;
  height: 24px;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  background-color: #ededed;
  position: relative;
  box-shadow: inset -1px 1px 3px rgba(0, 0, 0, .1);
}

.markdown-body .progress-label {
  position: absolute;
  text-align: center;
  font-weight: bold;
  width: 100%; margin: 0;
  line-height: 24px;
  color: #333;
  text-shadow: 1px 1px 0 #fefefe, -1px -1px 0 #fefefe, -1px 1px 0 #fefefe, 1px -1px 0 #fefefe, 0 1px 0 #fefefe, 0 -1px 0 #fefefe, 1px 0 0 #fefefe, -1px 0 0 #fefefe, 1px 1px 2px #000;
  -webkit-font-smoothing: antialiased !important;
  white-space: nowrap;
  overflow: hidden;
}

.markdown-body .progress-bar {
  height: 24px;
  float: left;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  background-color: #96c6d7;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), inset 0 -1px 0 rgba(0, 0, 0, .1);
  background-size: 30px 30px;
  background-image: -webkit-linear-gradient(
    135deg, rgba(255, 255, 255, .4) 27%,
    transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%,
    transparent 77%, transparent
  );
  background-image: -moz-linear-gradient(
    135deg,
    rgba(255, 255, 255, .4) 27%, transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%, transparent 77%,
    transparent
  );
  background-image: -ms-linear-gradient(
    135deg,
    rgba(255, 255, 255, .4) 27%, transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%, transparent 77%,
    transparent
  );
  background-image: -o-linear-gradient(
    135deg,
    rgba(255, 255, 255, .4) 27%, transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%, transparent 77%,
    transparent
  );
  background-image: linear-gradient(
    135deg,
    rgba(255, 255, 255, .4) 27%, transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%, transparent 77%,
    transparent
  );
}

.markdown-body .progress-100plus .progress-bar {
  background-color: #a6d796;
}

.markdown-body .progress-80plus .progress-bar {
  background-color: #c6d796;
}

.markdown-body .progress-60plus .progress-bar {
  background-color: #d7c896;
}

.markdown-body .progress-40plus .progress-bar {
  background-color: #d7a796;
}

.markdown-body .progress-20plus .progress-bar {
  background-color: #d796a6;
}

.markdown-body .progress-0plus .progress-bar {
  background-color: #c25f77;
}

.markdown-body .candystripe-animate .progress-bar{
  -webkit-animation: animate-stripes 3s linear infinite;
  -moz-animation: animate-stripes 3s linear infinite;
  animation: animate-stripes 3s linear infinite;
}

@-webkit-keyframes animate-stripes {
  0% {
    background-position: 0 0;
  }

  100% {
    background-position: 60px 0;
  }
}

@-moz-keyframes animate-stripes {
  0% {
    background-position: 0 0;
  }

  100% {
    background-position: 60px 0;
  }
}

@keyframes animate-stripes {
  0% {
    background-position: 0 0;
  }

  100% {
    background-position: 60px 0;
  }
}

.markdown-body .gloss .progress-bar {
  box-shadow:
    inset 0 4px 12px rgba(255, 255, 255, .7),
    inset 0 -12px 0 rgba(0, 0, 0, .05);
}

/* Multimarkdown Critic Blocks */
.markdown-body .critic_mark {
  background: #ff0;
}

.markdown-body .critic_delete {
  color: #c82829;
  text-decoration: line-through;
}

.markdown-body .critic_insert {
  color: #718c00 ;
  text-decoration: underline;
}

.markdown-body .critic_comment {
  color: #8e908c;
  font-style: italic;
}

.markdown-body .headeranchor {
  font: normal normal 16px octicons-anchor;
  line-height: 1;
  display: inline-block;
  text-decoration: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.headeranchor:before {
  content: '\f05c';
}

.markdown-body .task-list-item {
  list-style-type: none;
}

.markdown-body .task-list-item+.task-list-item {
  margin-top: 3px;
}

.markdown-body .task-list-item input {
  margin: 0 4px 0.25em -20px;
  vertical-align: middle;
}

/* Media */
@media only screen and (min-width: 480px) {
  .markdown-body {
    font-size:14px;
  }
}

@media only screen and (min-width: 768px) {
  .markdown-body {
    font-size:16px;
  }
}

@media print {
  .markdown-body * {
    background: transparent !important;
    color: black !important;
    filter:none !important;
    -ms-filter: none !important;
  }

  .markdown-body {
    font-size:12pt;
    max-width:100%;
    outline:none;
    border: 0;
  }

  .markdown-body a,
  .markdown-body a:visited {
    text-decoration: underline;
  }

  .markdown-body .headeranchor-link {
    display: none;
  }

  .markdown-body a[href]:after {
    content: " (" attr(href) ")";
  }

  .markdown-body abbr[title]:after {
    content: " (" attr(title) ")";
  }

  .markdown-body .ir a:after,
  .markdown-body a[href^="javascript:"]:after,
  .markdown-body a[href^="#"]:after {
    content: "";
  }

  .markdown-body pre {
    white-space: pre;
    white-space: pre-wrap;
    word-wrap: break-word;
  }

  .markdown-body pre,
  .markdown-body blockquote {
    border: 1px solid #999;
    padding-right: 1em;
    page-break-inside: avoid;
  }

  .markdown-body .progress,
  .markdown-body .progress-bar {
    -moz-box-shadow: none;
    -webkit-box-shadow: none;
    box-shadow: none;
  }

  .markdown-body .progress {
    border: 1px solid #ddd;
  }

  .markdown-body .progress-bar {
    height: 22px;
    border-right: 1px solid #ddd;
  }

  .markdown-body tr,
  .markdown-body img {
    page-break-inside: avoid;
  }

  .markdown-body img {
    max-width: 100% !important;
  }

  .markdown-body p,
  .markdown-body h2,
  .markdown-body h3 {
    orphans: 3;
    widows: 3;
  }

  .markdown-body h2,
  .markdown-body h3 {
    page-break-after: avoid;
  }
}
</style><title>platformio_tutorial</title></head><body><article class="markdown-body"><h1 id="platform-io"><a name="user-content-platform-io" href="#platform-io" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Platform IO 上手</h1>
<div class="toc">
<ul>
<li><a href="#platform-io">Platform IO 上手</a><ul>
<li><a href="#mbed">mbed 篇</a><ul>
<li><a href="#_1">准备材料</a></li>
<li><a href="#_2">新建工程</a></li>
<li><a href="#_3">例程</a><ul>
<li><a href="#_4">基础例程</a><ul>
<li><a href="#_5">串口</a></li>
</ul>
</li>
<li><a href="#mbed-os">mbed-os</a></li>
<li><a href="#_6">外设库</a></li>
</ul>
</li>
<li><a href="#_7">参考链接</a></li>
</ul>
</li>
<li><a href="#nodemcu">NodeMCU 篇</a><ul>
<li><a href="#_8">安装驱动</a></li>
<li><a href="#_9">新建工程</a></li>
<li><a href="#_10">例程</a><ul>
<li><a href="#_11">串口</a></li>
<li><a href="#homekit">HomeKit</a></li>
</ul>
</li>
<li><a href="#_12">更新固件</a></li>
<li><a href="#_13">参考链接</a></li>
</ul>
</li>
<li><a href="#arduino">Arduino 篇</a><ul>
<li><a href="#_14">参考链接</a></li>
</ul>
</li>
<li><a href="#_15">树莓派篇</a></li>
<li><a href="#_16">总结</a><ul>
<li><a href="#_17">优点：集大成者</a></li>
</ul>
</li>
<li><a href="#_18">不足</a></li>
</ul>
</li>
</ul>
</div>
<h2 id="mbed"><a name="user-content-mbed" href="#mbed" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>mbed 篇</h2>
<h3 id="_1"><a name="user-content-_1" href="#_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>准备材料</h3>
<ul>
<li>支持 mbed 的开发板子一块</li>
<li>mbed 开发者账号一个</li>
<li>可连接互联网的机子一台（Windows/Linux/ macOS）</li>
<li>Atom 及 Platform IO 开发环境 </li>
<li>各种外设硬件若干</li>
</ul>
<h3 id="_2"><a name="user-content-_2" href="#_2" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>新建工程</h3>
<p>待环境安装完成，按照如下步骤可新建一个跑马灯的工程：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_create_new.png" /></p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_create_blink_project_0.png" /></p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_create_blink_project.png" /></p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_create_blink_project_sucess_hint.png" /></p>
<p>点击 <code>Process</code> 之后，Platform IO 会自动根据所选择的平台下载编译环境和所需要的库，如此处分别为 <code>arm-gcc</code> 和 <code>mbed</code> 库文件，将其保存到 <code>~/.platformio</code> 文件夹下:</p>
<pre><code>➜  .platformio tree -d . -L 3
.
└── packages
    ├── framework-mbed
    │   ├── libs
    │   └── variant
    ├── ldscripts
    ├── tool-scons
    │   ├── engine
    │   └── script
    ├── tool-stlink
    └── toolchain-gccarmnoneeabi
        ├── arm-none-eabi
        ├── bin
        ├── lib
        └── share
</code></pre>

<p>然后，新建工程目录结构如下：</p>
<pre><code>➜  blink tree .
.
├── lib
│   └── readme.txt
├── platformio.ini
└── src
</code></pre>

<p>此时，在 <code>src</code> 中添加 <code>main.cpp</code>：</p>
<pre><code>#include &quot;mbed.h&quot;

DigitalOut myled(LED1);

int main() {
        while(1) {
                myled = 1; // LED is ON
                wait(0.2); // 200 ms
                myled = 0; // LED is OFF
                wait(1.0); // 1 sec
        }
}
</code></pre>

<p>编译之后，显示如下错误，但成功生成可执行文件：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_compile_error_stm32f4xx_hal_gpio_not_found.png" /></p>
<p>放狗一搜，同样有人碰到<a href="https://github.com/platformio/platformio-core/issues/621">此问题</a>，需要重新建立工程索引<code>PlatformIO &gt; Rebuild C/C++ Project Index (Autocomplete, Linter)</code>：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_rebuild_index.png" /></p>
<p>重新编译后，完美通过~</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_compile_sucess_after_reindex.png" /></p>
<p>点击上传可以将编译完成的<code>elf</code>上传到板子上，值得一提的是 Platform IO会自动寻找是否有支持 mbed 的板子，并将程序上传到板子上。</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_auto_upload.png" /></p>
<p>如果你不想 Platform IO 自己去找，也可以手动指定，修改 <code>platformio.ini</code>，增加<code>upload_port</code>板子的路径，如下：</p>
<pre><code>#
# PlatformIO Project Configuration File
#
# Please make sure to read documentation with examples first
# http://docs.platformio.org/en/stable/projectconf.html
#
[env:nucleo_f401re]
platform = ststm32
framework = mbed
board = nucleo_f401re

upload_port = /Volumes/NUCLEO

</code></pre>

<p>注：在下载程序的过程中，还不小心遇到了<code>SWD error</code>的问题，重新插拔 USB 线后恢复正常。</p>
<p>新建工程可以通过菜单栏来，也可以直接手动新建如上的工程结构，然后编译的是否 Platform IO 同样会自动寻找依赖并安装，显示如下：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_auto_download_env.png" /></p>
<h3 id="_3"><a name="user-content-_3" href="#_3" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>例程</h3>
<h4 id="_4"><a name="user-content-_4" href="#_4" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>基础例程</h4>
<h5 id="_5"><a name="user-content-_5" href="#_5" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>串口</h5>
<p>串口是调试的利器，特别在没有仿真器的时候。</p>
<p>在写串口模块程序前，先看看是否已经连接上，方法如下：<code>Platform IO</code>-&gt;<code>List Serial Ports</code></p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_list_serial.png" /></p>
<p>mbed 的串口程序非常简单，实例化一个 Serial 的实例即可，默认配置为波特率9600</p>
<pre><code>#include &quot;mbed.h&quot;

//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

Serial pc(SERIAL_TX, SERIAL_RX);

DigitalOut myled(LED1);

int main() {
        int i = 1;
        pc.printf(&quot;Hello World !\n&quot;);
        while(1) {
                wait(1);
                pc.printf(&quot;This program runs since %d seconds.\n&quot;, i++);
                myled = !myled;
        }
}
</code></pre>

<p>更新程序后，点击左侧的串口标志按钮，自动调出串口窗口如下：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_serial_default_config.png" /></p>
<p>按照默认配置即可：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_serial_msg_show.png" /></p>
<h4 id="mbed-os"><a name="user-content-mbed-os" href="#mbed-os" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>mbed-os</h4>
<p>mbed-os 版本的跑马灯</p>
<pre><code>#include &quot;mbed.h&quot;
#include &quot;rtos.h&quot;

/*
 * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
 * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
 * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
 */
#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
#define STACK_SIZE DEFAULT_STACK_SIZE/4
#else
#define STACK_SIZE DEFAULT_STACK_SIZE
#endif

void print_char(char c = '*') {
        printf(&quot;%c&quot;, c);
        fflush(stdout);
}

DigitalOut led1(LED1);
DigitalOut led2(LED2);

void led2_thread(void const *argument) {
        while (true) {
                led2 = !led2;
                Thread::wait(1000);
                print_char();
        }
}

int main() {
        Thread thread(led2_thread, NULL, osPriorityNormal, STACK_SIZE);

        while (true) {
                led1 = !led1;
                Thread::wait(500);
        }
}
</code></pre>

<h4 id="_6"><a name="user-content-_6" href="#_6" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>外设库</h4>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_install_pkg_118.png" /></p>
<h3 id="_7"><a name="user-content-_7" href="#_7" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参考链接</h3>
<h2 id="nodemcu"><a href="http://nodemcu.com/">NodeMCU</a> 篇</h2>
<h3 id="_8"><a name="user-content-_8" href="#_8" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>安装驱动</h3>
<p>由于购买时，那时还不晓得 NodeMCU 还有版本的不同，结果商家发的老版本的 v0.9 版本的，同学们购买时需要擦亮眼睛了。如下图中，左侧的是 v0.9 （有蓝色的和黄色的区别），右侧的是 v1.0 版本的：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/nodemcu-v0.9-vs-nodemcu-v1.0.jpg" /></p>
<p>注：其硬件上的主要区别在于，前者的 USB-Serial 采用 CH340；后者采用 CP2102 。买新不买旧么。</p>
<p>macOS EI Caption 及以上的驱动，请下载<a href="https://github.com/adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver">此处</a>。</p>
<p>安装后重启就可以找到如下的 USB 转串口的端口：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/nodemcu-ch34h-usb-serial.png" /></p>
<h3 id="_9"><a name="user-content-_9" href="#_9" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>新建工程</h3>
<p>新建一个跑马灯工程如下，初次使用时可能要等一会。</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/nodemcu-board-setting.png" /></p>
<p>由于 NodeMCU 是 Arduino 兼容的，所以可以直接使用按照 Arduino 的方式来对 NodeMCU 进行直接操作。</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/nodemcu-v0.9-pinout.png" /></p>
<p>Platform 官方也提供了一些例子，但是<a href="https://github.com/platformio/platformio-examples/blob/develop/espressif/esp32-arduino-blink/src/Blink.cpp">官方代码</a>好像是针对的 <code>v1.0</code> 的，用的 13 pin，但 <code>v0.9</code> 的 LED-Pin 引脚为16，不过对 Arduino 来说都是 <code>D0</code>，所以修改后兼容性更好了，修改后如下所示：</p>
<pre><code>/*
 * Blink
 * Turns on an LED on for one second,
 * then off for one second, repeatedly.
 */

#include &lt;Arduino.h&gt;

#define LED_BUILTIN D0

void setup()
{
  // initialize LED digital pin as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BUILTIN, HIGH);
  // wait for a second
  delay(1000);
  // turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, LOW);
   // wait for a second
  delay(1000);
}
</code></pre>

<p>编译提示如下：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/nodemcu-compile-success.png" /></p>
<p>然后上传到板子上：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/nodemcu-upload-success.png" /></p>
<p>板子上的小蓝灯就闪起来了。</p>
<h3 id="_10"><a name="user-content-_10" href="#_10" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>例程</h3>
<h4 id="_11"><a name="user-content-_11" href="#_11" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>串口</h4>
<p>直接上代码吧：</p>
<pre><code>#include &lt;Arduino.h&gt;

void setup() {
  Serial.begin(9600);
}

void loop() {
  delay(1000);
  Serial.println(&quot;Hello World!&quot;);
}
</code></pre>

<p>编译上传成功之后，需要先设置下串口如下：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/nodemcu-serial-setting.png" /></p>
<p>然后，打开串口窗口显示如下：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/nodemcu-helloworld.png" /></p>
<h4 id="homekit"><a name="user-content-homekit" href="#homekit" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>HomeKit</h4>
<p>安装 <a href="https://github.com/nfarina/homebridge">Homebridge</a> 和 <a href="https://github.com/rudders/homebridge-http">homebridge-http</a>：前者是模拟 HomeKit API 的一个模拟器，后者是将开关信息放在 URL 中的方式。</p>
<p>注：在这里，你可能会遇到无法下载，此时你需要翻墙；或者下载速度极其缓慢，此时你需要设置国内的 NPM 源；或者你可能会遇到版本过低，亦或是版本不兼容的问题，此时你需要去其 GiHub Issue 或者 Google 搜搜看。</p>
<p>惯例，用 <code>--version</code> 来确认是否安装成功。</p>
<pre><code>➜  ~ homebridge --version
0.4.16
➜  ~ 
</code></pre>

<p>然后，设置 <code>~/.homebridge/config.json</code>如下：</p>
<pre><code>{
    &quot;bridge&quot;: {
        &quot;name&quot;: &quot;Homebridge&quot;,
        &quot;username&quot;: &quot;CC:22:3D:E3:CE:30&quot;,
        &quot;port&quot;: 51826,
        &quot;pin&quot;: &quot;031-45-154&quot;
    },

    &quot;description&quot;: &quot;Config file with just lockitron&quot;,

    &quot;accessories&quot;: [
        {
            &quot;accessory&quot;: &quot;Http&quot;,
            &quot;name&quot;: &quot;NodeMCU1.0 LED&quot;,
            &quot;http_method&quot;: &quot;GET&quot;,
            &quot;on_url&quot;:      &quot;http://192.168.1.122/ledon&quot;,
            &quot;off_url&quot;:     &quot;http://192.168.1.122/ledoff&quot;,
            &quot;service&quot;: &quot;Light&quot;
       },
        {
            &quot;accessory&quot;: &quot;Http&quot;,
            &quot;name&quot;: &quot;NodeMCU0.9 LED&quot;,
            &quot;http_method&quot;: &quot;GET&quot;,
            &quot;on_url&quot;:      &quot;http://192.168.1.120/ledon&quot;,
            &quot;off_url&quot;:     &quot;http://192.168.1.120/ledoff&quot;,
            &quot;service&quot;: &quot;Light&quot;
       }
    ]
}
</code></pre>

<p>注：其中的<code>http://192.168.1.120</code>需自行替换为实际的局域网 IP 地址；这里放两个是因为我有两块板子，实际按需放就好了。</p>
<p>最后，启动 <code>homebridge</code>  就可以了：</p>
<pre><code>➜  ~ homebridge 
[1/2/2017, 9:00:20 PM] Loaded plugin: homebridge-http
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-http.Http'
[1/2/2017, 9:00:20 PM] ---
[1/2/2017, 9:00:20 PM] Loaded plugin: homebridge-httptemperaturehumidity
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-httptemperaturehumidity.HttpTemphum'
[1/2/2017, 9:00:20 PM] ---
[1/2/2017, 9:00:20 PM] Loaded plugin: homebridge-legacy-plugins
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.AD2USB'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.Carwings'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.ELKM1'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.FileSensor'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.GenericRS232Device'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.HomeMatic'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.HomeMaticThermo'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.HomeMaticWindow'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.HttpGarageDoorOpener'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.HttpHygrometer'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.HttpThermometer'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.Tesla'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.X10'
[1/2/2017, 9:00:20 PM] Registering accessory 'homebridge-legacy-plugins.mpdclient'
[1/2/2017, 9:00:20 PM] Registering platform 'homebridge-legacy-plugins.Domoticz'
[1/2/2017, 9:00:20 PM] Registering platform 'homebridge-legacy-plugins.HomeAssistant'
[1/2/2017, 9:00:20 PM] Registering platform 'homebridge-legacy-plugins.HomeSeer'
[1/2/2017, 9:00:20 PM] Registering platform 'homebridge-legacy-plugins.ISY'
[1/2/2017, 9:00:20 PM] Registering platform 'homebridge-legacy-plugins.LIFx'
[1/2/2017, 9:00:20 PM] Registering platform 'homebridge-legacy-plugins.SmartThings'
[1/2/2017, 9:00:20 PM] Registering platform 'homebridge-legacy-plugins.TelldusLive'
[1/2/2017, 9:00:20 PM] Registering platform 'homebridge-legacy-plugins.ZWayServer'
[1/2/2017, 9:00:20 PM] ---
[1/2/2017, 9:00:21 PM] Loaded plugin: homebridge-lockitron
[1/2/2017, 9:00:21 PM] Registering accessory 'homebridge-lockitron.Lockitron'
[1/2/2017, 9:00:21 PM] ---
[1/2/2017, 9:00:21 PM] Loaded plugin: homebridge-mqttswitch
[1/2/2017, 9:00:21 PM] Registering accessory 'homebridge-mqttswitch.mqttswitch'
[1/2/2017, 9:00:21 PM] ---
[1/2/2017, 9:00:21 PM] Loaded config.json with 2 accessories and 0 platforms.
[1/2/2017, 9:00:21 PM] ---
[1/2/2017, 9:00:21 PM] Loading 2 accessories...
[1/2/2017, 9:00:21 PM] [NodeMCU1.0 LED] Initializing Http accessory...
[1/2/2017, 9:00:21 PM] [NodeMCU0.9 LED] Initializing Http accessory...
Scan this code with your HomeKit App on your iOS device to pair with Homebridge:

    ┌────────────┐     
    │ 031-45-154 │     
    └────────────┘     

[1/2/2017, 9:00:21 PM] Homebridge is running on port 51826.
</code></pre>

<p>此时，打开 iPhone 或者 iPad （iOS10+）的 Home 应用，就会显示如下的两个按钮：</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platform_tutorial_homebridge_home.png" /></p>
<p>至于，NodeMCU 端的代码，在官方版本的 <a href="https://github.com/platformio/platformio-examples/blob/develop/espressif/esp8266-webserver/src/HelloServer.ino">WebServer</a>基础上进行如下稍微修改即可：</p>
<pre><code>
void led_on(void) {
        digitalWrite(led, 0);
        server.send(200, &quot;text/plain&quot;, &quot;on&quot;);
}

void led_off(void) {
        digitalWrite(led, 1);
        server.send(200, &quot;text/plain&quot;, &quot;off&quot;);
}

  ...
void setup(void){
        server.on(&quot;/&quot;, handleRoot);

        // for HomkeKit post
        server.on(&quot;/ledon&quot;, led_on);
        server.on(&quot;/ledoff&quot;,led_off);
      }
  ...
</code></pre>

<p>编译，下载后，就可以通过 Home 界面的按钮来进行控制了。</p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platform_tutorial_homekit_switch.GIF" /></p>
<p>终端输出的信息如下：</p>
<pre><code>
    ┌────────────┐     
    │ 031-45-154 │     
    └────────────┘     

[1/2/2017, 9:32:12 PM] Homebridge is running on port 51826.
[1/2/2017, 9:32:20 PM] [NodeMCU1.0 LED] Setting power state to on
[1/2/2017, 9:32:20 PM] [NodeMCU1.0 LED] HTTP set power function succeeded!


[1/2/2017, 9:32:23 PM] [NodeMCU1.0 LED] Setting power state to off
[1/2/2017, 9:32:24 PM] [NodeMCU1.0 LED] HTTP set power function succeeded!
</code></pre>

<h3 id="_12"><a name="user-content-_12" href="#_12" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>更新固件</h3>
<h3 id="_13"><a name="user-content-_13" href="#_13" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参考链接</h3>
<ul>
<li><a href="https://github.com/platformio/platformio-examples/tree/develop/espressif">platformio-examples-espressif</a></li>
<li><a href="https://github.com/adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver">CH340G CH34G CH34X Mac OS X driver</a></li>
<li><a href="https://tzapu.com/making-ch340-ch341-serial-adapters-work-under-el-capitan-os-x/">CH340 CH341 serial adapters fix for El Capitan OS X</a></li>
<li><a href="https://github.com/nodemcu/nodemcu-devkit/wiki/Getting-Started-on-OSX">Getting Started on OSX</a></li>
<li><a href="https://www.losant.com/blog/getting-started-with-platformio-esp8266-nodemcu">GETTING STARTED WITH PLATFORMIO AND ESP8266 NODEMCU</a></li>
<li><a href="https://github.com/nodemcu/nodemcu-firmware">nodemcu-firmware</a>: A Lua based firmware for ESP8266 WiFi SOC</li>
<li><a href="http://learn.acrobotic.com/tutorials/post/esp8266-getting-started">Getting Started: NodeMCU ESP8266 Development Board</a></li>
<li><a href="http://www.cnx-software.com/2015/10/29/getting-started-with-nodemcu-board-powered-by-esp8266-wisoc/">Getting Started with NodeMCU Board Powered by ESP8266 WiSoC</a></li>
</ul>
<h2 id="arduino"><a name="user-content-arduino" href="#arduino" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Arduino 篇</h2>
<p><img alt="from https://lynx2015.files.wordpress.com/2015/08/arduino-mega-pinout-diagram.png" src="http://mint-blog.qiniudn.com/arduino-mega-2560-pinout-diagram.png" /></p>
<p><img alt="" src="http://mint-blog.qiniudn.com/platformio_tutorial_auto_download_env_arduino.png" /></p>
<h3 id="_14"><a name="user-content-_14" href="#_14" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参考链接</h3>
<ul>
<li><a href="https://www.arduino.cc/en/Main/arduinoBoardMega2560">Arduino MEGA 2560 &amp; Genuino MEGA 2560</a></li>
<li><a href="http://www.arduino.org/learning/getting-started/getting-started-with-arduino-mega-2560">Start with Arduino Mega 2560</a></li>
<li><a href="http://www.atmel.com/Images/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf">ATmega2560 datasheet</a></li>
</ul>
<h2 id="_15"><a name="user-content-_15" href="#_15" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>树莓派篇</h2>
<h2 id="_16"><a name="user-content-_16" href="#_16" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>总结</h2>
<h3 id="_17"><a name="user-content-_17" href="#_17" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>优点：集大成者</h3>
<ul>
<li>可以选择自己喜欢的编辑器，然后配置下插件环境即可，是原版在线和 IDE 的良好替代品，得益于 Atom 的好用和 Clang 的强大，比如<ul>
<li>好用的自动代码补全和定义跳转</li>
<li>集成串口窗口，直接查看</li>
<li>友好的错误和警告提示</li>
</ul>
</li>
<li>同平台跨板子的支持很好，可以通过 <code>platformio.ini</code> 配置好，然后编译即可完成， Platform IO 就会自动下载相关依赖，这也得益于 Arduino 和 mbed 的良好抽象架构</li>
<li>方便使用各种库，包括 Arduino 和 mbed</li>
</ul>
<h2 id="_18"><a name="user-content-_18" href="#_18" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>不足</h2>
<ul>
<li>无法在线单步调试，只能通过串口打印来</li>
<li>需要单片机板子支持 Arduino 或者 mbed</li>
</ul>
<p>另外，Platform IO 和 mbed-os 都处在快速的迭代过程中（既是好事，也是不足），碰到问题直接放狗搜索，然后一般都会定位到官方的社区或者 GitHub Issue 中找到类似的解决方案。</p>
<p>不过，目前蛮多的解决方案也是比较粗暴的，比如遇到一个<code>NUCLEO_F401RE.eix not found</code>的问题，找到<a href="https://community.platformio.org/t/enabling-nucleo-f401re-in-platformio/670">类似</a>，维护者的解决方案是直接把 Platform 的配置目录给全部删除，然后再重新下载。</p></article></body></html>